<template>
  <div class="login_container">
    <div class="login_form">
      <div class="avatar_box">
        <img
          src="http://destiny001.gitee.io/admin-dist/img/logo.b5a855ee.png"
          alt=""
        />
      </div>
      <div class="login_box">
        <el-form ref="userForm" :model="form" :rules="rules">
          <el-form-item prop="username">
            <el-input prefix-icon="el-icon-user-solid" v-model.trim="form.username" placeholder="请输入用户名" ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input prefix-icon="el-icon-lock" type="password" show-password placeholder="请输入密码" v-model.trim="form.password"></el-input>
          </el-form-item>
          <el-form-item label-width="260px">
            <el-button type="primary" @click="submitForm('form')"
              >登录</el-button
            >
            <el-button type="info" @click="resetForm('userForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { goLogin } from '@/api/user.js'
export default {
  data () {
    return {
      form: {
        username: 'admin',
        password: '123456'
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名称', trigger: 'blur' },
          { min: 3, max: 7, message: '长度在 3 到 7 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },

  created () {},

  methods: {
    async submitForm () {
      try {
        const res = await goLogin(this.form)
        this.$store.commit('setUser', res.data.data)
        this.$router.push('/welcome')
      } catch (err) {

      }
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped lang="less">
.login_container {
  background-color: #2b4b6b;
  height: 100%;
  width: 100%;
  position: relative;
  .login_form {
    background-color: #fff;
    position: absolute;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    width: 450px;
    height: 300px;
    border-radius: 3px;
    top: 50%;
    .avatar_box {
      height: 130px;
      width: 130px;
      border: 1px solid #eee;
      border-radius: 50%;
      padding: 10px;
      -webkit-box-shadow: 0 0 10px #ddd;
      box-shadow: 0 0 10px #ddd;
      background-color: #fff;
      position: absolute;
      left: 50%;
      -webkit-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .login_box {
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 0 20px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      .fm_btn{

      }
    }
  }
}
</style>
